package guice

import java.nio.file.Paths

//import com.kongming.kmdm.common.mq.MQUtils
//import com.kongming.kmdm.configure.KmdmCommonConfigure
//import com.kongming.kmdm.configure.impl.KmdmCommonConfigureImpl
//import com.kongming.kmdm.service.channel.IMsgChannelService
//import com.kongming.kmdm.service.channel.impl.MsgChannelServiceImpl
//import com.kongming.utils.config.CommonConfigure
//import com.kongming.utils.ioc.provider.MongoSession
//import com.kongming.utils.ioc.provider.MongoSessionProvider
import org.mongodb.morphia.Morphia
import org.quartz.Scheduler
import org.quartz.impl.StdSchedulerFactory
import org.quartz.spi.JobFactory
import play.api.ApplicationLoader.Context
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.guice.GuiceApplicationLoader
import play.api.inject.guice.GuiceableModule


/**
  * Created by fanqiang on 17/3/1.
  */
class DataCenterApplicationLoader extends GuiceApplicationLoader {
  override protected def builder(context: Context): GuiceApplicationBuilder =
    super.builder(context).overrides(DataCenterApplicationLoader.defaultOverrides: _*)
}

object DataCenterApplicationLoader {
  def defaultOverrides: Seq[GuiceableModule] = {
    val path = Paths.get("").toAbsolutePath + "/conf/config.properties" replace ("datacenter/datacenter", "datacenter")
//    val configure = KmdmCommonConfigureImpl.getInstance(path)
//    MQUtils.init(path)
//    val jobScheduler = StdSchedulerFactory.getDefaultScheduler
    Seq(
//      bind[KmdmCommonConfigure] to configure,
//      bind[CommonConfigure] to configure,
      bind[Morphia] to new Morphia
//      bind[MongoSession] toProvider classOf[MongoSessionProvider],
//      bind[Scheduler] to jobScheduler,
//      bind[IMsgChannelService] toInstance new MsgChannelServiceImpl(path),
//      bind[JobFactory] to classOf[ElementalJobFactory]
    )
  }
}
